package com.un.ebs.sys.controller;


import com.un.ebs.core.util.WebResult;
import com.un.ebs.core.util.WebUtils;
import com.un.ebs.sys.dto.EntDeptAddDto;
import com.un.ebs.sys.dto.EntDeptUpdateDto;
import com.un.ebs.sys.dto.ObjectParentAndIndexChangeDto;
import com.un.ebs.sys.mapper.EntDeptMapper;
import com.un.ebs.sys.service.EntDeptService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author liubo
 * @since 2019-09-15
 */
@RestController
@RequestMapping("/entDept")
@Api(value = "sys-ent-dept", description = "部门")
public class EntDeptController {

    @Autowired
    private EntDeptService service;

    @Autowired
    private EntDeptMapper entDeptMapper;

    @PostMapping("add")
    @ApiOperation(value = "add", notes = "添加")
    public WebResult save(@RequestBody EntDeptAddDto req) {
        service.add(req);
        return WebUtils.success();
    }

    @PostMapping("update")
    @ApiOperation(value = "update", notes = "修改")
    public WebResult update(@RequestBody EntDeptUpdateDto req) {
        service.update(req);
        return WebUtils.success();
    }

    @GetMapping("/{id}")
    @ApiOperation(value = "getById", notes = "根据主键获取单个 EntDept")
    public WebResult getById(@PathVariable("id") String id) {
        return WebUtils.success(service.queryById(id));
    }

    @GetMapping("list/{entId}")
    @ApiOperation(value = "list", notes = "")
    public WebResult list(@PathVariable("entId") String entId) {
        return WebUtils.success(service.queryByEntId(entId));
    }

    @PostMapping("delete/{id}")
    @ApiOperation(value = "delete", notes = "根据主键删除单个 EntDept")
    public WebResult delete(@PathVariable("id") String id) {
        service.delete(id);
        return WebUtils.success();
    }

    @PostMapping("changeNodes")
    @ApiOperation("批量排序")
    public WebResult changeNodes(@RequestBody List<ObjectParentAndIndexChangeDto> req) {
        service.changeNode(req);
        return WebUtils.success();
    }

}